﻿using System;

namespace BingoServerCommon.Log4net
{
	/// <summary>
	/// log4net 日志框架的简单应用，很实用。
	/// </summary>
	public class LogHelper
	{
		private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(LogHelper));

		public static void WriteFatal(Exception e = null)
		{
			if (e != null) Log.Fatal($"{e.Message} \n {e.StackTrace}");
		}

		public static void WriteFatal(string msg, Exception e = null)
		{
			Log.Fatal(e == null ? msg : $"{msg}\n {e.Message} \n {e.StackTrace}");
		}


		public static void WriteError(Exception e = null)
		{
			if (e != null) Log.Fatal($"{e.Message} \n {e.StackTrace}");
		}

		public static void WriteError(string msg, Exception e = null)
		{
			Log.Error(e == null ? msg : $"{msg}\n {e.Message} \n {e.StackTrace}");
		}


		public static void WriteWarn(Exception e = null)
		{
			if (e != null) Log.Warn($"{e.Message} \n {e.StackTrace}");
		}
		public static void WriteWarn(string msg, Exception e = null)
		{
			Log.Warn(e == null ? msg : $"{msg}\n {e.Message} \n {e.StackTrace}");
		}


		public static void WriteDebug(Exception e = null)
		{
			if (e != null) Log.Debug($"{e.Message} \n {e.StackTrace}");
		}

		public static void WriteDebug(string msg, Exception e = null)
		{
			Log.Debug(e == null ? msg : $"{msg}\n {e.Message} \n {e.StackTrace}");
		}


		public static void WriteInfo(Exception e = null)
		{
			if (e != null) Log.Info($"{e.Message} \n {e.StackTrace}");
		}

		public static void WriteInfo(string msg, Exception e = null)
		{
			Log.Info(e == null ? msg : $"{msg}\n {e.Message} \n {e.StackTrace}");
		}
	}
}
